<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>
        {% block title %}城会玩 - 注册{% endblock %}
    </title>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/static/js/jquery_2.1.4_jquery.min.js"></script>
    <!-- BootStrap -->
    <script src="/static/js/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
        <!-- Bootstrap -->
    <link rel="stylesheet" href="/static/js/bootstrap-3.4.1-dist/css/bootstrap.min.css">
    <style>
        :root {
            --primary: #FF6B35;
            --primary-dark: #e55a2b;
            --primary-light: rgba(255, 107, 53, 0.1);
            --secondary: #2A9D8F;
            --light: #F8F9FA;
            --dark: #343A40;
            --accent: #E9C46A;
            --gradient-primary: linear-gradient(135deg, #FF6B35 0%, #FF8E53 100%);
            --gradient-secondary: linear-gradient(135deg, #2A9D8F 0%, #44C2B3 100%);
            --gradient-hero: linear-gradient(135deg, rgba(255, 107, 53, 0.92) 0%, rgba(233, 196, 106, 0.85) 100%);
            --shadow: 0 10px 30px rgba(0,0,0,0.1);
            --shadow-hover: 0 15px 40px rgba(0,0,0,0.15);
            --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            overflow-x: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .register-container {
            width: 100%;
            max-width: 1100px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            min-height: 650px;
            border-radius: 24px;
            overflow: hidden;
            box-shadow: var(--shadow-hover);
            animation: fadeInUp 0.8s ease-out forwards;
            opacity: 0;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .hero-section {
            background: var(--gradient-hero);
            color: white;
            padding: 3rem 2.5rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        .hero-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 100" fill="rgba(255,255,255,0.1)"><polygon points="1000,100 1000,0 0,100"/></svg>');
            background-size: cover;
        }

        .hero-content {
            position: relative;
            z-index: 2;
        }

        .hero-title {
            font-size: 40px;
            font-weight: 700;
            margin-bottom: 1rem;
            line-height: 1.2;
        }

        .hero-subtitle {
            font-size: 14px;
            margin-bottom: 2rem;
            opacity: 0.9;
            line-height: 1.6;
        }

        .features-grid {
            display: grid;
            gap: 1rem;
            margin-top: 2rem;
        }

        .feature-item {
            display: flex;
            align-items: center;
            gap: 1rem;
            padding: 0.75rem;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            backdrop-filter: blur(10px);
            transition: var(--transition);
        }

        .feature-item:hover {
            background: rgba(255, 255, 255, 0.15);
            transform: translateX(5px);
        }

        .feature-icon {
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .feature-text h3 {
            margin: 0 0 0.25rem 0;
            font-size: 20px;
        }

        .feature-text p {
            margin: 0;
            font-size: 14px;
            opacity: 0.8;
        }

        .form-section {
            background: white;
            padding: 2rem 2rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
            overflow-y: auto;
            align-items: center;
        }

        .form-header {
            text-align: center;
            margin-bottom: 1.5rem;
        }

        .form-title {
            font-size: 30px;
            font-weight: 600;
            color: var(--dark);
            margin-bottom: 0.5rem;
        }

        .form-subtitle {
            color: #6c757d;
            font-size: 14px;
        }

        .form-group {
            margin-bottom: 1rem;
            position: relative;
            align-items: center;
            display: flex;
            flex-direction: column;
            width: 100%;
        }

        .input-with-icon {
            position: relative;
            display: flex;
            justify-content: center;
            width: 100%;
        }

        /* 调整图标位置 - 核心修改点 */
        .input-icon {
            position: absolute;
            left: 18px; /* 图标与输入框左侧的距离，比原来更靠内 */
            top: 50%;
            transform: translateY(-50%);
            color: #6c757d;
            z-index: 2;
            transition: var(--transition);
            font-size: 16px; /* 图标大小调整 */
        }

        .form-control {
            border: 2px solid #e9ecef;
            border-radius: 12px;
            padding: 10px 16px 10px 44px; /* 左侧内边距减少，让文字更靠近图标 */
            font-size: 14px;
            transition: var(--transition);
            background: #fafbfc;
            width: 350px;
            font-family: inherit;
            height: 44px;
            align-items: center;
            margin: 0 auto;
        }

        .form-control:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px var(--primary-light);
            background: white;
            outline: none;
        }

        .form-control:focus ~ .input-icon {
            color: var(--primary);
        }

        /* 验证码区域调整 */
        .verification-group {
            position: relative;
            width: 100%;
            display: flex;
            justify-content: center;
        }

        .verification-input {
            width: 100%;
        }

        .verification-input .form-control {
            padding-right: 110px; /* 给右侧按钮预留空间 */
        }

        .send-code-btn {
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 10px;
            padding: 0 16px;
            white-space: nowrap;
            transition: var(--transition);
            font-weight: 500;
            cursor: pointer;
            font-size: 13px;
            height: 38px;
            position: absolute;
            right: 8px; /* 按钮与输入框右侧的距离 */
            top: 50%;
            transform: translateY(-50%);
            z-index: 3;
            min-width: 90px;
        }

        .send-code-btn:hover:not(:disabled) {
            background: var(--primary-dark);
            transform: translateY(-50%) scale(1.05);
            box-shadow: 0 3px 10px rgba(255, 107, 53, 0.2);
        }

        .send-code-btn:disabled {
            background: #6c757d;
            cursor: not-allowed;
            transform: translateY(-50%);
            box-shadow: none;
        }

        .btn-register {
            background: var(--gradient-primary);
            border: none;
            border-radius: 12px;
            padding: 12px;
            font-weight: 600;
            font-size: 14px;
            width: 350px;
            margin: 1rem 0 0.5rem;
            transition: var(--transition);
            color: white;
            cursor: pointer;
            font-family: inherit;
            position: relative;
            overflow: hidden;
            height: 46px;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }

        .btn-register:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(255, 107, 53, 0.3);
        }

        .btn-login-link {
            background: transparent;
            color: var(--primary);
            border: 2px solid var(--primary);
            border-radius: 12px;
            padding: 10px;
            font-weight: 600;
            font-size: 14px;
            width: 350px;
            transition: var(--transition);
            cursor: pointer;
            font-family: inherit;
            height: 44px;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }

        .btn-login-link:hover {
            background: var(--primary);
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(255, 107, 53, 0.2);
        }

        .password-strength {
            height: 3px;
            background: #e9ecef;
            border-radius: 2px;
            margin-top: 5px;
            overflow: hidden;
            transition: var(--transition);
        }

        .password-strength-bar {
            height: 100%;
            width: 0%;
            background: var(--primary);
            transition: width 0.3s ease, background 0.3s ease;
            border-radius: 2px;
        }

        .terms-agreement {
            background: var(--primary-light);
            border: 1px solid rgba(255, 107, 53, 0.2);
            border-radius: 12px;
            padding: 10px;
            margin: 1rem 0;
            text-align: center;
            transition: var(--transition);
        }

        .terms-text {
            font-size: 1.1rem;
            color: #6c757d;
            margin: 0;
            line-height: 1.4;
        }

        .terms-text a {
            color: var(--primary);
            text-decoration: none;
            font-weight: 500;
        }

        .alert {
            border-radius: 12px;
            padding: 0.8rem 1rem;
            margin-bottom: 1rem;
            border: none;
            animation: fadeIn 0.5s ease-out forwards;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .particles-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            z-index: 1;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            body {
                padding: 10px;
                align-items: flex-start;
            }

            .register-container {
                grid-template-columns: 1fr;
                max-width: 500px;
                min-height: auto;
            }

            .hero-section {
                padding: 2rem 1.5rem;
                order: 2;
            }

            .form-section {
                padding: 2rem 1rem;
            }

            .hero-title {
                font-size: 32px;
            }

            .features-grid {
                grid-template-columns: 1fr;
            }

            .form-control, .btn-register, .btn-login-link {
                width: 100%;
                max-width: 350px;
            }

            .verification-group {
                width: 100%;
                max-width: 350px;
            }
        }

        @media (max-width: 480px) {
            .hero-section, .form-section {
                padding: 1.5rem 1rem;
            }

            .hero-title {
                font-size: 28px;
            }

            .form-title {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="register-container">
        <!-- 左侧英雄区域 -->
        <div class="hero-section">
            <div class="particles-container" id="particles"></div>
            <div class="hero-content">
                <h1 class="hero-title">加入城会玩</h1>
                <p class="hero-subtitle">注册账号，开启精彩的本地社交生活，与志同道合的朋友相遇</p>

                <div class="features-grid">
                    <div class="feature-item">
                        <div class="feature-icon">
                            📅
                        </div>
                        <div class="feature-text">
                            <h3>活动丰富</h3>
                            <p>每日更新各类本地活动，总有你感兴趣的</p>
                        </div>
                    </div>
                    <div class="feature-item">
                        <div class="feature-icon">
                            👥
                        </div>
                        <div class="feature-text">
                            <h3>活跃社区</h3>
                            <p>与志同道合的朋友交流分享，拓展社交圈</p>
                        </div>
                    </div>
                    <div class="feature-item">
                        <div class="feature-icon">
                            📍
                        </div>
                        <div class="feature-text">
                            <h3>本地推荐</h3>
                            <p>基于位置推荐最适合你的活动和场所</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 右侧注册表单 -->
        <div class="form-section">
            <div class="form-header">
                <h1 class="form-title">创建账号</h1>
                <p class="form-subtitle">请填写您的注册信息</p>
            </div>

            <form class="auth-form" action="/user/register/" method="post" id="registerForm">
                {% csrf_token %}

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="text" class="form-control" id="inputUsername"
                               placeholder="创建您的专属昵称" name="username" required>
                        <span class="input-icon">👤</span>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="email" class="form-control" id="inputEmail"
                               placeholder="请输入有效邮箱" name="email" required>
                        <span class="input-icon">📧</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label">邮箱验证码</label>
                    <div class="verification-group">
                        <div class="input-with-icon verification-input">
                            <input type="text" class="form-control"
                                   id="emailVerifyCode" placeholder="6位验证码"
                                   name="email_verify_code" required maxlength="6">
                            <span class="input-icon">✨</span>
                        </div>
                        <button type="button" class="send-code-btn" id="sendVerificationBtn">
                            发送验证码
                        </button>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="password" class="form-control" id="inputPassword"
                               placeholder="设置登录密码" name="password" required>
                        <span class="input-icon">🔒</span>
                    </div>
                    <div class="password-strength">
                        <div class="password-strength-bar" id="passwordStrengthBar"></div>
                    </div>
                    <small class="text-muted" id="passwordStrengthText">密码强度：未输入</small>
                </div>

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="password" class="form-control" id="inputPassword2"
                               placeholder="再次输入密码" name="password2" required>
                        <span class="input-icon">🔒</span>
                    </div>
                    <small class="text-muted" id="passwordMatchText" style="display: none;"></small>
                </div>

                <div class="terms-agreement">
                    <p class="terms-text">
                        注册即表示同意
                        <a href="/terms/" target="_blank">服务条款</a>
                        和
                        <a href="/privacy/" target="_blank">隐私政策</a>
                        ，邮箱用于密码找回和安全验证
                    </p>
                </div>

                {% if msg %}
                    <div class="alert alert-danger">{{ msg }}</div>
                {% endif %}
                {% if success_msg %}
                    <div class="alert alert-success">{{ success_msg }}</div>
                {% endif %}

                <button type="submit" class="btn-register" id="registerBtn">
                    立即注册
                </button>

                <button type="button" class="btn-login-link" onclick="window.location.href='/user/login/'">
                    已有账号？立即登录
                </button>
            </form>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 创建粒子背景
            function createParticles() {
                const container = document.getElementById('particles');
                const particleCount = 15;

                for (let i = 0; i < particleCount; i++) {
                    const particle = document.createElement('div');
                    particle.className = 'particle';
                    particle.style.cssText = `
                        position: absolute;
                        background: rgba(255,255,255,0.6);
                        border-radius: 50%;
                        animation: float ${Math.random() * 4 + 4}s ease-in-out infinite;
                        opacity: 0;
                        width: ${Math.random() * 6 + 2}px;
                        height: ${Math.random() * 6 + 2}px;
                        left: ${Math.random() * 100}%;
                        top: ${Math.random() * 100}%;
                        animation-delay: ${Math.random() * 5}s;
                    `;

                    setTimeout(() => {
                        particle.style.opacity = Math.random() * 0.4 + 0.2;
                    }, Math.random() * 1000);

                    container.appendChild(particle);
                }
            }

            createParticles();

            const passwordInput = document.getElementById('inputPassword');
            const confirmPasswordInput = document.getElementById('inputPassword2');
            const passwordStrengthBar = document.getElementById('passwordStrengthBar');
            const passwordStrengthText = document.getElementById('passwordStrengthText');
            const passwordMatchText = document.getElementById('passwordMatchText');
            const sendVerificationBtn = document.getElementById('sendVerificationBtn');
            const registerBtn = document.getElementById('registerBtn');

            // 密码强度检测
            passwordInput.addEventListener('input', function() {
                const password = this.value;
                let strength = 0;
                let text = '密码强度：未输入';
                let color = '#dc3545';

                if (password.length >= 6) {
                    strength += 25;
                    text = '密码强度：较弱';
                    color = '#dc3545';
                }
                if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {
                    strength += 25;
                    text = '密码强度：一般';
                    color = '#fd7e14';
                }
                if (/[0-9]/.test(password)) {
                    strength += 25;
                    text = '密码强度：良好';
                    color = '#20c997';
                }
                if (/[^a-zA-Z0-9]/.test(password)) {
                    strength += 25;
                    text = '密码强度：优秀';
                    color = '#198754';
                }

                passwordStrengthBar.style.width = strength + '%';
                passwordStrengthText.textContent = text;
                passwordStrengthBar.style.background = color;

                checkPasswordMatch();
            });

            // 确认密码验证
            confirmPasswordInput.addEventListener('input', checkPasswordMatch);

            function checkPasswordMatch() {
                const password = passwordInput.value;
                const confirmPassword = confirmPasswordInput.value;

                if (confirmPassword.length === 0) {
                    passwordMatchText.style.display = 'none';
                    return;
                }

                passwordMatchText.style.display = 'block';

                if (password === confirmPassword && password.length > 0) {
                    passwordMatchText.textContent = '✓ 密码匹配';
                    passwordMatchText.className = 'text-success';
                    registerBtn.disabled = false;
                } else {
                    passwordMatchText.textContent = '✗ 密码不匹配';
                    passwordMatchText.className = 'text-danger';
                    registerBtn.disabled = true;
                }
            }

            // 发送验证码
            sendVerificationBtn.addEventListener('click', function() {
                const email = document.getElementById('inputEmail').value.trim();
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

                if (!email) {
                    showNotification('请输入邮箱地址', 'error');
                    return;
                }

                if (!emailRegex.test(email)) {
                    showNotification('请输入有效的邮箱地址', 'error');
                    return;
                }

                // 禁用按钮，开始倒计时
                sendVerificationBtn.disabled = true;
                let countdown = 60;

                const timer = setInterval(() => {
                    sendVerificationBtn.textContent = `${countdown}秒后重发`;
                    countdown--;

                    if (countdown < 0) {
                        clearInterval(timer);
                        sendVerificationBtn.disabled = false;
                        sendVerificationBtn.textContent = '发送验证码';
                    }
                }, 1000);

                // 发送验证码逻辑
                const formData = new FormData();
                formData.append('email', email);
                formData.append('type', 'register');

                fetch('/user/send_verify_code/', {
                    method: 'POST',
                    body: formData,
                    headers: {
                        'X-CSRFToken': getCSRFToken()
                    }
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        showNotification(data.message, 'success');
                    } else {
                        showNotification(data.message, 'error');
                        clearInterval(timer);
                        sendVerificationBtn.disabled = false;
                        sendVerificationBtn.textContent = '发送验证码';
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    showNotification('发送验证码时发生错误', 'error');
                    clearInterval(timer);
                    sendVerificationBtn.disabled = false;
                    sendVerificationBtn.textContent = '发送验证码';
                });
            });

            // 获取CSRF token
            function getCSRFToken() {
                const name = 'csrftoken';
                let cookieValue = null;
                if (document.cookie && document.cookie !== '') {
                    const cookies = document.cookie.split(';');
                    for (let i = 0; i < cookies.length; i++) {
                        const cookie = cookies[i].trim();
                        if (cookie.substring(0, name.length + 1) === (name + '=')) {
                            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                            break;
                        }
                    }
                }
                return cookieValue;
            }

            // 显示通知函数
            function showNotification(message, type = 'info') {
                const existingNotification = document.querySelector('.custom-notification');
                if (existingNotification) {
                    existingNotification.remove();
                }

                const notification = document.createElement('div');
                notification.className = `alert alert-${type === 'error' ? 'danger' : 'success'} custom-notification`;
                notification.style.cssText = `
                    position: fixed;
                    top: 20px;
                    right: 20px;
                    z-index: 1050;
                    animation: slideInRight 0.3s ease-out forwards;
                    border-radius: 12px;
                    padding: 1rem 1.25rem;
                    border: none;
                    font-weight: 500;
                    max-width: 300px;
                `;

                const icon = type === 'error' ? '⚠️' : '✅';
                notification.innerHTML = `${icon} ${message}`;

                document.body.appendChild(notification);

                setTimeout(() => {
                    notification.style.animation = 'slideOutRight 0.3s ease-in forwards';
                    setTimeout(() => {
                        if (notification.parentNode) {
                            document.body.removeChild(notification);
                        }
                    }, 300);
                }, 3000);
            }

            // 自动聚焦到用户名输入框
            setTimeout(() => {
                const usernameInput = document.getElementById('inputUsername');
                if (usernameInput) {
                    usernameInput.focus();
                }
            }, 500);
        });
    </script>
</body>
</html>